/*     */ package com.newcrm.businessarchives;
/*     */ 
/*     */ import com.newcrm.exception.CaptchaException;
/*     */ import com.newcrm.util.Util;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintStream;
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jsoup.Connection;
/*     */ import org.jsoup.Jsoup;
/*     */ import org.jsoup.nodes.Document;
/*     */ import org.jsoup.nodes.Element;
/*     */ import org.jsoup.select.Elements;
/*     */ 
/*     */ public class TaizhouSearchEngine extends SearchEngine
/*     */ {
/*  21 */   private static Logger logger = Logger.getLogger(TaizhouSearchEngine.class
/*  22 */     .getName());
/*     */ 
/*  24 */   private Map<String, String> params = new HashMap();
/*     */ 
/*     */   public TaizhouSearchEngine(String name) {
/*  27 */     this.name = standardizedName(name);
/*     */ 
/*  29 */     this.params.put("市场主体名称", "CompanyName");
/*  30 */     this.params.put("注册号", "SN");
/*  31 */     this.params.put("法定代表人", "Header");
/*  32 */     this.params.put("成立日期", "FoundedDate");
/*  33 */     this.params.put("企业类型", "CompanyType");
/*  34 */     this.params.put("注册资本(万元)", "RegisteredCapital");
/*  35 */     this.params.put("登记机关", "RegistrationAuthority");
/*  36 */     this.params.put("住所", "Address");
/*     */   }
/*     */ 
/*     */   public static void main(String[] args)
/*     */     throws CaptchaException
/*     */   {
/*  44 */     TaizhouSearchEngine searchEngine = new TaizhouSearchEngine(
/*  45 */       "泰州市江中化工有限公司");
/*  46 */     Map items = searchEngine.getCompanyByWeb();
/*  47 */     System.out.println(items);
/*     */   }
/*     */ 
/*     */   protected Map<String, Object> getCompanyByWeb()
/*     */     throws CaptchaException
/*     */   {
/*  53 */     if (!isValid(this.name)) {
/*  54 */       return null;
/*     */     }
/*  56 */     String url = null;
/*     */     try {
/*  58 */       url = "http://www.tzgsj.gov.cn/baweb/show/shiju/business_query.jsp?flag=2&fenceid=1&businessName=" + URLEncoder.encode(this.name.trim(), "utf-8");
/*     */     } catch (UnsupportedEncodingException e) {
/*  60 */       url = "http://www.tzgsj.gov.cn/baweb/show/shiju/business_query.jsp?flag=2&fenceid=1&businessName=" + this.name.trim();
/*     */     }
/*     */     try {
/*  63 */       Document doc = Jsoup.connect(url).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)")
/*  64 */         .timeout(60000).get();
/*  65 */       Elements links = doc
/*  66 */         .select("td[style=border-bottom:1px dashed gray] a");
/*  67 */       String detailUrl = null;
/*  68 */       if ((links != null) && (links.size() >= 1)) {
/*  69 */         detailUrl = links.get(0).absUrl("href");
/*     */       }
/*     */ 
/*  72 */       if ((detailUrl == null) || (detailUrl.trim().length() == 0))
/*     */       {
/*  74 */         JiangsuSearchEngine search = new JiangsuSearchEngine(this.name);
/*  75 */         return search.getCompanyByWeb();
/*     */       }
/*     */ 
/*  80 */       doc = Jsoup.connect(detailUrl).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)").timeout(10000)
/*  81 */         .get();
/*  82 */       links = doc.select("table[class=detail] th");
/*  83 */       if (links == null) {
/*  84 */         return null;
/*     */       }
/*     */ 
/*  87 */       Map info = new HashMap();
/*  88 */       String businessScope = "";
/*  89 */       for (Element item : links) {
/*  90 */         String key = item.text().trim();
/*  91 */         String value = item.nextElementSibling().select("input")
/*  92 */           .attr("value");
/*     */ 
/*  94 */         if (key.equals("许可经营项目")) {
/*  95 */           businessScope = businessScope + 
/*  96 */             item.nextElementSibling().select("textarea")
/*  97 */             .text();
/*     */         }
/* 101 */         else if (key.equals("一般经营项目")) {
/* 102 */           businessScope = businessScope + 
/* 103 */             item.nextElementSibling().select("textarea")
/* 104 */             .text();
/*     */         }
/* 108 */         else if (key.equals("经营期限")) {
/* 109 */           info.put("OperatingPeriod", value + 
/* 110 */             " - " + 
/* 111 */             item.nextElementSibling().nextElementSibling()
/* 112 */             .select("input").attr("value"));
/*     */         }
/* 116 */         else if (this.params.containsKey(key))
/*     */         {
/* 119 */           info.put((String)this.params.get(key), value);
/*     */         }
/*     */       }
/*     */ 
/* 123 */       info.put("BusinessScope", businessScope);
/* 124 */       info.put("RegisteredCapital", info.get("RegisteredCapital") + "万元");
/* 125 */       info.put("UpdateDate", Util.date2Str(new Date()));
/* 126 */       if (info.size() > 1)
/*     */       {
/* 128 */         saveDB(info);
/*     */       }
/*     */ 
/* 131 */       return info;
/*     */     } catch (IOException e) {
/* 133 */       logger.warn("get company from web failed", e);
/*     */     }
/*     */ 
/* 136 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.businessarchives.TaizhouSearchEngine
 * JD-Core Version:    0.6.1
 */